﻿<%@ Page Title="Recipe Details - Traditional Maltese Cuisine" Language="C#" MasterPageFile="~/MainMasterPage.Master" AutoEventWireup="true" CodeBehind="Details.aspx.cs" Inherits="TraditionalMalteseCuisine.Details" %>
<%@ Register Namespace="ASPnetRater" Assembly="ASPnetRater" TagPrefix="cc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <asp:ValidationSummary ID="vsyValidationSummary" runat="server" HeaderText="Please note that:" CssClass="validation_summary" />
    <asp:Label ID="lblMessage" runat="server" CssClass="successful_message" Visible="false" Text="Recipe updated successfully" />
    <div id="control_wrapper" style="width: 80%;">
        <table style="width: 100%;">
            <tr><td colspan="4">
                <div class="title">
                    <% if (IsOwner) { %>
                    <span class="label">Recipe Name:</span>&nbsp;&nbsp;<asp:TextBox ID="txtRecipeName" runat="server" CssClass="textbox" Width="80%" />
                    <asp:RequiredFieldValidator ID="rfvRecipeName" runat="server" ErrorMessage="RecipeName field cannot be empty" ControlToValidate="txtRecipeName" SetFocusOnError="True" >*</asp:RequiredFieldValidator>
                    <% } else { %>
                    <% Response.Write(CurrentRecipe); %>
                    <% } %>
                </div>
                <asp:LinkButton ID="btnDislike" runat="server" CssClass="button dislike_button" CausesValidation="False" Text="Unlike" Visible="False" OnClick="btnDislike_Click" />
                <asp:LinkButton ID="btnLike" runat="server" CssClass="button like_button" CausesValidation="False" Text="Like" Visible="False" OnClick="btnLike_Click" />
                </td>
            </tr>
            <% if ((!IsOwner) && (IsLoggedIn)) { %>
            <tr>
                <td colspan="3" class="label">Rate Recipe:</td>
                <td class="top_justify label" >
                    <div id="rating_cntrol">
                        <b style="float: right;"><% Response.Write(GetRatingStatistics()); %></b>
                        <!--
                            For some reason I was not able to install the Ajax Control Toolkit so I could not use the RatingContol
                            that comes with the toolkit. After some research on-line I found a suitable replacement. Full credit
                            should go to the creator for the ASPnetRater control.

                            Created By: taihip
                            Posted On-line on: 19 Apr 2011
                            Link to source code: http://www.codeproject.com/Articles/35155/ASP-NET-Rating-Control

                            I simply download the project from the above article, added the project to my solution and than
                            referenced the control in my Details.aspx page. The only changes I did was to use my own images
                            to represent the rating.
                        -->
                        <cc:Rater ID="rtrRatingControl" runat="server" ImageOff="SiteContentImages\NoRating.png" Value="0" MaxValue="5" ImageOn="SiteContentImages\Rating.png" ToolTip="Rate this recipe" OnCommand="rtrRatingControl_Command" ImageOver="SiteContentImages\Rating.png" />
                    </div>
                </td>
            </tr>
            <% } else { %>
            <tr>
                <td colspan="3" class="label">Average Rating:</td>
                <td class="middle_justify" style="padding: 10px;"><b><% Response.Write(GetRatingStatistics()); %></b></td>
            </tr>
            <% } %>
            <tr>
                <td class="label top_right">Author:</td>
                <td colspan="2" class="textbox top_justify" style="padding-right: 10px;">
                    <a href='<% Response.Write(string.Format("profile.aspx?user={0}", CurrentRecipe.MemberID)); %>'><% Response.Write(GetAuthorName()); %></a>
                </td>
                <td rowspan="5" class="top_center" style="padding-right: 10px;">
                    <img src='<% Response.Write(CurrentRecipe.ImageLocation); %>' alt='<% Response.Write(string.Format("{0}'s", CurrentRecipe)); %>' style="max-width: 250px" />
                    <% if (IsOwner) { %>
                    <asp:FileUpload ID="uplImageLocation" runat="server" CssClass="textbox" /><asp:CustomValidator ID="csvImageLocation" runat="server" ErrorMessage="Please choose a valid image file" ControlToValidate="uplImageLocation">&nbsp;*</asp:CustomValidator>
                    <% } %>
                </td>
            </tr>
            <tr>
                <td class="label top_right">Member Level:</td>
                <td colspan="2" class="textbox top_justify"><a href="BoardLeadersInPostedRecipes.aspx" style="text-decoration: none;"><% Response.Write(GetContributionLevelForRecipesPosted()); %></a></td>
            </tr>
            <tr>
                <td class="label top_right">Recipe Level:</td>
                <td colspan="2" class="textbox top_justify" style="padding-right: 10px;"><a href='<% Response.Write(string.Format("recipes.aspx?level={0}", CurrentRecipe.LevelID)); %>'><% Response.Write(GetLevelText()); %></a></td>
            </tr>
            <tr><td colspan="3">&nbsp;</td></tr>
            <tr>
                <td class="label top_right">Description:</td>
                <% if (IsOwner) { %>
                <td class="top_left" style="width: 80%;"><asp:TextBox ID="txtDescription" runat="server" CssClass="memobox" TextMode="MultiLine" Height="150px" /></td>
                <td class="top_left"><asp:RequiredFieldValidator ID="rfvDescription" runat="server" ErrorMessage="Description field cannot be empty" ControlToValidate="txtDescription" SetFocusOnError="True" >*</asp:RequiredFieldValidator></td>
                <% } else { %>
                <td colspan="2" class="textbox top_justify" style="padding-right: 20px;"><% Response.Write(string.Format("{0}", CurrentRecipe.Description.Replace("\n", "<br />"))); %></td>
                <% } %>
            </tr>
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr>
                <td class="label top_right">Directions:</td>
                <% if (IsOwner) { %>
                <td class="top_left" style="width: 80%;"><asp:TextBox ID="txtDirections" runat="server" CssClass="memobox" TextMode="MultiLine" Height="150px" /></td>
                <td class="top_left"><asp:RequiredFieldValidator ID="rfvDirections" runat="server" ErrorMessage="Directions field cannot be empty" ControlToValidate="txtDirections" SetFocusOnError="True" >*</asp:RequiredFieldValidator></td>
                <td rowspan="3" class="top_left" style="width: 38%;"><div class="checked_listbox" style="max-height: 335px;"><asp:CheckBoxList ID="clsTags" runat="server" /></div></td>
                <% } else { %>
                <td colspan="2" class="textbox top_justify" style="padding-right: 20px;"><% Response.Write(string.Format("{0}", CurrentRecipe.Directions.Replace("\n", "<br />"))); %></td>
                <td rowspan="3" class="top_left"><span class="label">Ingredients:</span><br /><br /><% Response.Write(string.Format("{0}", CurrentRecipe.Ingredients.Replace("\n", "<br />"))); %></td>
                <% } %>
            </tr>
            <tr><td colspan="3">&nbsp;</td></tr>
            <tr>
                <% if (IsOwner) { %>
                <td class="label top_right">Ingredients:</td>
                <td class="top_left" style="width: 80%;"><asp:TextBox ID="txtIngredients" runat="server" CssClass="memobox" TextMode="MultiLine" Height="150px" /></td>
                <td class="top_left"><asp:RequiredFieldValidator ID="rfvIngredients" runat="server" ErrorMessage="Ingredients field cannot be empty" ControlToValidate="txtIngredients" SetFocusOnError="True" >*</asp:RequiredFieldValidator></td>
                <% } else { %>
                <td colspan="3">&nbsp;</td>
                <% } %>
            </tr>
            <% if (IsOwner) { %>
            <tr>
                <td class="middle_right"><asp:Label ID="lblLevel" runat="server" Text="Level:" CssClass="label" /></td>
                <td class="middle_left" style="width: 60%;">
                    <asp:DropDownList ID="cmbLevel" runat="server" CssClass="combobox" />
                    <asp:RequiredFieldValidator ID="rfvLevel" runat="server" ErrorMessage="Level field cannot be empty" ControlToValidate="cmbLevel" SetFocusOnError="True" >*</asp:RequiredFieldValidator>
                </td>
                <td class="top_right"><asp:Label ID="lblTag" runat="server" Text="New Tag(s):" CssClass="label" /></td>
                <td class="top_left" style="width: 60%;"><asp:TextBox ID="txtTags" runat="server" CssClass="textbox" Width="75%" ToolTip="Use ',' to specify more than one" /><asp:Button ID="btnAddTags" runat="server" Text="Add" CssClass="button" CausesValidation="False" OnClick="btnAddTags_Click" UseSubmitBehavior="False" /></td>
            </tr>
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr><td colspan="4" class="middle_center"><asp:Button ID="btnUpdate" runat="server" Text="Update" CssClass="button" OnClick="btnUpdate_Click" UseSubmitBehavior="False" /></td></tr>
            <% } else { %>
            <tr>
                <td colspan="3" class="textbox bottom_left">
                    <p>Tags for this recipe: <% Response.Write(GetStringTags()); %></p>
                    <p style="text-align: right;">Posted on: <% Response.Write(string.Format("{0:dd-MMM-yyyy HH:mm}", CurrentRecipe.PostedDate)); %></p>
                </td>
                <td>
                    <span class="label"><br /><br />Supermarkets in Malta:</span><br /><br />
                    <iframe src="https://mapsengine.google.com/map/embed?mid=zPSdnXUv3bcg.kUiVokL1QWRc" width="320" height="240"></iframe>
                </td>
            </tr>
            <% } %>
        </table>
        <br />
        <asp:UpdatePanel ID="updCommentsPanel" runat="server">
            <ContentTemplate>
                <% if (IsLoggedIn) { %>
                <hr style="width: 85%;" />
                <br />
                <div id="leave_comment">
                    <div id="leave_comment_row">
                        <div id="leave_comment_label">Leave a Comment:</div>
                        <div id="leave_comment_text"><asp:TextBox ID="txtComments" runat="server" CssClass="memobox" TextMode="MultiLine" Height="95px" Width="100%" /></div>
                        <div id="leave_comment_footer"><asp:Button ID="btnSubmitComment" runat="server" Text="Submit Comment" CssClass="button" OnClick="btnSubmitComment_Click" CausesValidation="false" UseSubmitBehavior="False" /></div><br />
                    </div>
                </div>
                <% } %>
                <br />
                <hr style="width: 85%;" />
                <br />
                <asp:Repeater ID="rptComments" runat="server" OnItemCommand="rptComments_ItemCommand">
                    <HeaderTemplate><div id="comments_listing"></HeaderTemplate>
                    <ItemTemplate>
                        <a href='<%# string.Format("profile.aspx?user={0}", Eval("member_id")) %>'>
                            <div id="comments_row">
                                <div id="comments_user_info">
                                    <div style="float: left;"><img src='<%# Eval("avatar").ToString() %>' alt="Click to visit profile..." class="profile_thumbnail_image" /></div>
                                    <div style="padding-left: 5px; float: left;">
                                        <%# string.Format("{0} {1}", Eval("firstname"), Eval("lastname")) %><br />
                                        <a href='mailto:<%# string.Format("{0}", Eval("email")) %>' style="text-decoration: underline; font-size: 11px;"><%# string.Format("{0}", Eval("email")) %></a>
                                    </div>
                                    <div id="comments_user_info_awards"><%# string.Format("{0}", GetContributionLevelForRecipesCommentsPosted(int.Parse(Eval("member_id").ToString())))%></div>
                                </div>
                                <div id="comments_header">Posted on: <%# string.Format("{0:dd-MMM-yyyy HH:mm}", Eval("posted_date")) %></div>
                                <div id="comments_text"><%# string.Format("{0}", Eval("comment").ToString().Replace("\n", "<br />")) %></div>
                                <div id="comments_remove"><asp:LinkButton ID="btnRemoveComment" runat="server" ToolTip="Delete your comment" CssClass="top_left button remove_comment_button" CausesValidation="False" CommandName="Click" CommandArgument='<%# Eval("comment_id") %>' OnClientClick="return confirm('Are you sure you want to delete your comment?');" Visible='<%# IsOwnComment(int.Parse(Eval("member_id").ToString())) %>' /></div>
                            </div>
                        </a>
                    </ItemTemplate>
                    <FooterTemplate></div></FooterTemplate>
                </asp:Repeater>
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
    </div>
</asp:Content>
